import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { NzMessageService, NzModalRef, NzModalService } from 'ng-zorro-antd';

@Injectable()
export class UtilService {
  loodImgUrl:string ='http://upload.lessonplan.cn';//图片上传地址
  readImgUrl = 'http://static.lessonplan.cn/';
  temUrl='http://templateserver.lessonplan.cn';
  staticUrl = 'http://static.lessonplan.cn';
  accountUrl = 'http://accountserver.lessonplan.cn';
  classUrl = `http://rosterserver.lessonplan.cn`;
  canvasurl = 'http://canvasserver.lessonplan.cn';
  codeUrl='http://codeserver.lessonplan.cn';
  index=8;//swot分析
  canvasconfig = {
    1: {
      guid: '17aa4b10-d8cd-5ba0-bb52-42ae70fe9cf8',
      img: 'wenti.png',
      name: '提问树',
      path: 'questiontree.lessonplan.cn',
      english: 'Question Tree Canvas',
      appguid: 'c97790d3-0ded-4c36-8556-c7616799ad01',
      projectName:'tc'
    },
    2: {
      guid: '7ea5e62f-bdab-9260-bb5e-49d1572bf663',
      img: 'shu.png',
      name: '问题风暴',
      path: 'questionstorm.lessonplan.cn',
      english: 'Question Storm',
      appguid: '307386ce-99a8-a0fd-6221-5c37af9c1a70',
      projectName:'qc'
    },
    3: {
      guid: '63e2caab-0688-959c-d74f-063b73332184',
      img: 'jiazhi.png',
      name: '价值设计',
      path: 'valuedesign.lessonplan.cn',
      english: 'Value Design Canvas',
      appguid: '3c71511e-63b2-4b9a-bd64-1d5e63ff16ea',
      projectName:'vc'
    },
    4: {
      guid: '30d40de0-ab64-ca27-f0ee-0f7106d5bb15',
      img: 'maodun.png',
      name: 'TRIZ矛盾矩阵画布',
      path: 'triz.lessonplan.cn',
      english: 'Contradiction Matrix Canvas',
      appguid: 'c399ddc9-c158-4435-b2a7-a816408c7341',
      projectName:'rc'
    },
    5: {
      guid: '2c978a81-4807-68bc-27c3-1bf6ced74ff5',
      img: 'shangye.png',
      name: '商业画布',
      path: 'businessmodel.lessonplan.cn',
      english: 'Business Model Canvas',
      appguid: 'b1fda4b1-50c9-4273-ac2b-958ccfac264e',
      projectName:'bc'
    },
    6: {
      guid: 'add1e0fc-348e-ab64-c7e4-90b5638711db',
      img: 'tounao.png',
      name: '头脑风暴',
      path: 'brainstorming.lessonplan.cn',
      english: 'Brain Storming Canvas',
      appguid: '719d6c03-0dcd-4d09-a400-12ed7f77bfc1',
      projectName:'sc'
    },
    7: {
      guid: '62a77744-d5ab-6cbf-8de7-a30fde4e0e53',
      img: 'liuxiang.png',
      name: '六顶思考帽',
      path: 'sixthinkingcaps.lessonplan.cn',
      english: 'Six Thinking Cap Canvas',
      appguid: 'd0dbaf6a-a658-46aa-9966-906c7e196f3d',
      projectName:'oc'
    },
    8: {
      guid: '40dd26be-3707-3249-6e79-717d4024d290',
      img: 'swot.png',
      name: 'SWOT分析',
      path: 'swot.lessonplan.cn',
      english: 'SWOT',
      appguid: '7ba7b365-ef51-a52a-9185-cc7117c18869',
      projectName:'mc'
    },
    9: {
      guid: "560fb0f8-c3d7-671d-481a-d7c39d4c2e85",
      img: 'checklist.png',
      name: '奥斯本检核表法',
      path: 'checklist.lessonplan.cn',
      english: 'Osborn Checklist Method',
      appguid: 'ddf8ab2f-63a6-baf1-6d7d-99b4d60c570e',
      projectName:'ac'
    }
  };
  //配置
  constructor(
    private http: HttpClient,
    private modal: NzModalService,
    private message: NzMessageService
  ) { }
  canvas() {
    return this.canvasconfig[this.index]
  }
  GetUser(PK_UserGuid): Promise<any> {
    return this.http.get(`${this.accountUrl}/open/getThisUser?PK_UserGuid=${PK_UserGuid}`).toPromise().then(res => {
      return res;
    })
  }
  createCode(data): Promise<any> {
    return this.http.post(`${this.codeUrl}/api/create`,data).toPromise().then(res => {
      return res;
    })
  }
  reverse(guid): Promise<any> {
    return this.http.get(`${this.codeUrl}/api/reverse/${guid}`).toPromise().then(res => {
      return res;
    })
  }
  comfirm(text: string, callback): void {
    let confirmModal: NzModalRef;
    confirmModal = this.modal.confirm({
      nzTitle: text,
      nzOnOk: () => {
        callback();
      }
    });
  }
  comfirm2(text: string, callback, callback2): void {
    let confirmModal: NzModalRef;
    confirmModal = this.modal.confirm({
      nzTitle: text,
      nzOnOk: () => {
        callback();
      },
      nzOnCancel: () => {
        callback2();
      }
    });
  }

  remind(type: string, text: string): void {
    this.message.create(type, text);
  }

  getUserInfo(): Promise<any> {
    return new Promise((resolve, reject) => {
      resolve({status: 1, userGuid: '0c3d6e88-9f3e-4b57-ef5e-d3e3fec7130c'})
    })
    // return this.http.get(`/api/userInfo`).toPromise().then(res => {
    //   return res;
    // })
  }

  logout(): Promise<any> {
    return this.http.get(`/logout`).toPromise().then(res => {
      return res;
    })
  }
  /*路由守卫*/
  IsCanEnterApp(UserGuid): Promise<any> {
    return this.http.get(`${this.temUrl}/PurchaseRecord/IsCanEnterApp?UserGuid=${UserGuid}&FK_AppGuid=7ce0857b-9a10-40a3-b1fb-66dc6680d1da`)
      .toPromise().then(res => { return res })
  }
  //当前时间的时间戳
  timestamp(date) {
    return Date.parse(date ? date : new Date()) / 1000
  }
}
